package com.qdlc.p2p.dal.dto;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.common.util.OrderNoUtils;
import com.qdlc.p2p.dal.util.UserUtils;

/**
 * 第三方处理记录
 *
 * @author liya
 * @version 1.1.0.0
 */
@Entity
@Table(name = Global.DB_PREFIX + "tpp")
public class Tpp {

    /** 主键 */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /** 1:成功，2:失败，0:未触发 */
    private int status;

    /** 接口类型 */
    private String serviceType;

    /** 请求接口类型 */
    private String tppType;

    /** 用户 */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;

    /** 用户第三方账户 */
    private String tppUserCustId;

    /** 收款用户id */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "to_user_id")
    private User toUser;

    /** 收款用户第三方账户id */
    private String toTppUserCustId;

    /** 交易金额 */
    private double money;

    /** 服务费 * */
    private double servFee;

    /** p2p系统交易流水号 */
    private String orderId;

    /** p2p交易时间 */
    private String orderDate;

    /** 第三方订单号 */
    private String subOrdId;

    /** 第三方交易时间 */
    private String subOrdDate;

    /** 第三方冻结流水号 */
    private String trxId;

    /** 银行卡号 */
    private String bankCardId;

    /** 证件号 */
    private String cardId;

    /** 证件类型 */
    private String idType;

    /** 手机号 */
    private String phone;

    /** 邮箱 */
    private String email;

    /** 前台回调url */
    private String retUrl;

    /** 后台回调url */
    private String bgRetUrl;

    /** 投标对象 */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "borrow_id")
    private Borrow borrow;

    /** 投标对象 */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tender_id")
    private BorrowTender tender;

    /** 扩展参数 */
    private String extended;

    /** 取现复核标识 */
    private String flag;
    
    /** 交易类型 */
    private String tradeType;

    /** 回调结果 */
    private String respDesc;

    /** 触发时间* */
    private Date addTime;

    /** 投资项目id */
    private String tppBorrowId;


    /** 关联订单号 */
    private String associateOrderId;

    public Tpp() {
    }

    public Tpp(String cmdid, double ordamt, User user, User toUser, int status,
               Date addtime, String serviceType) {
        super();
        this.tppType = cmdid;
        this.money = ordamt;
        this.user = user;
        this.toUser = toUser;
        this.status = status;
        this.addTime = addtime;
        this.serviceType = serviceType;
    }

    /**
     * TPP构造函数
     *
     * @param serviceType 平台操作类型
     * @param tppType     第三方服务类型
     * @param user        付款方
     * @param toUser      收款方
     * @param money       交易金额
     * @param tender      关联投标
     */
    public Tpp(String serviceType, String tppType, User user, User toUser, double money, BorrowTender tender) {
        super();
        this.serviceType = serviceType;
        this.tppType = tppType;
        this.user = user;
        if (user != null)
            this.tppUserCustId = UserUtils.getUserTppCustId(user.getUserId());
        this.toUser = toUser;
        if (toUser != null)
            this.toTppUserCustId = UserUtils.getUserTppCustId(toUser.getUserId());
        this.money = money;
        this.tender = tender;
        this.orderId = OrderNoUtils.getSerialNumber();
        this.orderDate = DateUtil.dateStr7(DateUtil.getNow());
        this.addTime = DateUtil.getNow();
    }

    /**
     * 构造方法，第三方订单号根据传输的存储
     *
     * @param serviceType
     * @param tppType
     * @param user
     * @param toUser
     * @param money
     * @param
     */
    public Tpp(String serviceType, String tppType, User user, User toUser, double money, BorrowTender tender, String subOrdId, String borrowId) {
        this.serviceType = serviceType;
        this.tppType = tppType;
        this.user = user;
        if (user != null)
            this.tppUserCustId = UserUtils.getUserTppCustId(user.getUserId());
        this.toUser = toUser;
        if (toUser != null)
            this.toTppUserCustId = UserUtils.getUserTppCustId(toUser.getUserId());
        this.tender = tender;
        this.money = money;
        this.tppBorrowId = borrowId;
        this.orderId = subOrdId;
        this.subOrdId = subOrdId;
        this.orderDate = DateUtil.dateStr7(DateUtil.getNow());
        this.addTime = DateUtil.getNow();
    }


    public String getServiceType() {
        return serviceType;
    }

    public void setServiceType(String serviceType) {
        this.serviceType = serviceType;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getTppUserCustId() {
        return tppUserCustId;
    }

    public void setTppUserCustId(String tppUserCustId) {
        this.tppUserCustId = tppUserCustId;
    }

    public User getToUser() {
        return toUser;
    }

    public void setToUser(User toUser) {
        this.toUser = toUser;
    }

    public String getToTppUserCustId() {
        return toTppUserCustId;
    }

    public void setToTppUserCustId(String toTppUserCustId) {
        this.toTppUserCustId = toTppUserCustId;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public double getServFee() {
        return servFee;
    }

    public void setServFee(double servFee) {
        this.servFee = servFee;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getOrderDate() {
        return orderDate;
    }

    public void setOrderDate(String orderDate) {
        this.orderDate = orderDate;
    }

    public String getSubOrdId() {
        return subOrdId;
    }

    public void setSubOrdId(String subOrdId) {
        this.subOrdId = subOrdId;
    }

    public String getSubOrdDate() {
        return subOrdDate;
    }

    public void setSubOrdDate(String subOrdDate) {
        this.subOrdDate = subOrdDate;
    }

    public String getTrxId() {
        return trxId;
    }

    public void setTrxId(String trxId) {
        this.trxId = trxId;
    }

    public String getBankCardId() {
        return bankCardId;
    }

    public void setBankCardId(String bankCardId) {
        this.bankCardId = bankCardId;
    }

    public String getCardId() {
        return cardId;
    }

    public void setCardId(String cardId) {
        this.cardId = cardId;
    }

    public String getIdType() {
        return idType;
    }

    public void setIdType(String idType) {
        this.idType = idType;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getRetUrl() {
        return retUrl;
    }

    public void setRetUrl(String retUrl) {
        this.retUrl = retUrl;
    }

    public String getBgRetUrl() {
        return bgRetUrl;
    }

    public void setBgRetUrl(String bgRetUrl) {
        this.bgRetUrl = bgRetUrl;
    }

    public Borrow getBorrow() {
        return borrow;
    }

    public void setBorrow(Borrow borrow) {
        this.borrow = borrow;
    }

    public BorrowTender getTender() {
        return tender;
    }

    public void setTender(BorrowTender tender) {
        this.tender = tender;
    }


    public String getExtended() {
        return extended;
    }

    public void setExtended(String extended) {
        this.extended = extended;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getTppType() {
        return tppType;
    }

    public void setTppType(String tppType) {
        this.tppType = tppType;
    }

    public String getRespDesc() {
        return respDesc;
    }

    public void setRespDesc(String respDesc) {
        this.respDesc = respDesc;
    }

    public String getTppBorrowId() {
        return tppBorrowId;
    }

    public void setTppBorrowId(String tppBorrowId) {
        this.tppBorrowId = tppBorrowId;
    }

    public String getAssociateOrderId() {
        return associateOrderId;
    }

    public void setAssociateOrderId(String associateOrderId) {
        this.associateOrderId = associateOrderId;
    }

	public String getTradeType() {
		return tradeType;
	}

	public void setTradeType(String tradeType) {
		this.tradeType = tradeType;
	}
}
